﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:NJL_LOCAL_COLOR_NEWS
	/// </summary>
	public partial class NJL_LOCAL_COLOR_NEWS:INJL_LOCAL_COLOR_NEWS
	{
		public NJL_LOCAL_COLOR_NEWS()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from NJL_LOCAL_COLOR_NEWS");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_LOCAL_COLOR_NEWS model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into NJL_LOCAL_COLOR_NEWS(");
			strSql.Append("ID,NJL_LOCAL_COLOR_ID,SEO_TITLE,SEO_KEYWORDS,SEO_DESCRIPTION,NEWS_TITLE,NEWS_SUBJECT_TITLE,NEWS_CONTECT,NEWS_TAG,CREATE_DATE_TIME,CREATE_USER_ID,CREATE_USER_NAME,UPDATE_DATE_TIME,UPDATE_USER_ID,UPDATE_USER_NAME,SORT,VISIT_COUNT,COMMENT_COUNT,LAST_COMMENT_DATE_TIME,LAST_VISIT_DATE_TIME,IMAGE_CODE)");
			strSql.Append(" values (");
			strSql.Append("@ID,@NJL_LOCAL_COLOR_ID,@SEO_TITLE,@SEO_KEYWORDS,@SEO_DESCRIPTION,@NEWS_TITLE,@NEWS_SUBJECT_TITLE,@NEWS_CONTECT,@NEWS_TAG,@CREATE_DATE_TIME,@CREATE_USER_ID,@CREATE_USER_NAME,@UPDATE_DATE_TIME,@UPDATE_USER_ID,@UPDATE_USER_NAME,@SORT,@VISIT_COUNT,@COMMENT_COUNT,@LAST_COMMENT_DATE_TIME,@LAST_VISIT_DATE_TIME,@IMAGE_CODE)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_LOCAL_COLOR_ID", SqlDbType.VarChar,20),
					new SqlParameter("@SEO_TITLE", SqlDbType.VarChar,200),
					new SqlParameter("@SEO_KEYWORDS", SqlDbType.VarChar,200),
					new SqlParameter("@SEO_DESCRIPTION", SqlDbType.VarChar,500),
					new SqlParameter("@NEWS_TITLE", SqlDbType.VarChar,100),
					new SqlParameter("@NEWS_SUBJECT_TITLE", SqlDbType.VarChar,1000),
					new SqlParameter("@NEWS_CONTECT", SqlDbType.Text),
					new SqlParameter("@NEWS_TAG", SqlDbType.VarChar,200),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@SORT", SqlDbType.Int,4),
					new SqlParameter("@VISIT_COUNT", SqlDbType.Int,4),
					new SqlParameter("@COMMENT_COUNT", SqlDbType.Int,4),
					new SqlParameter("@LAST_COMMENT_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@LAST_VISIT_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@IMAGE_CODE", SqlDbType.VarChar,500)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.NJL_LOCAL_COLOR_ID;
			parameters[2].Value = model.SEO_TITLE;
			parameters[3].Value = model.SEO_KEYWORDS;
			parameters[4].Value = model.SEO_DESCRIPTION;
			parameters[5].Value = model.NEWS_TITLE;
			parameters[6].Value = model.NEWS_SUBJECT_TITLE;
			parameters[7].Value = model.NEWS_CONTECT;
			parameters[8].Value = model.NEWS_TAG;
			parameters[9].Value = model.CREATE_DATE_TIME;
			parameters[10].Value = model.CREATE_USER_ID;
			parameters[11].Value = model.CREATE_USER_NAME;
			parameters[12].Value = model.UPDATE_DATE_TIME;
			parameters[13].Value = model.UPDATE_USER_ID;
			parameters[14].Value = model.UPDATE_USER_NAME;
			parameters[15].Value = model.SORT;
			parameters[16].Value = model.VISIT_COUNT;
			parameters[17].Value = model.COMMENT_COUNT;
			parameters[18].Value = model.LAST_COMMENT_DATE_TIME;
			parameters[19].Value = model.LAST_VISIT_DATE_TIME;
			parameters[20].Value = model.IMAGE_CODE;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_LOCAL_COLOR_NEWS model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update NJL_LOCAL_COLOR_NEWS set ");
			strSql.Append("NJL_LOCAL_COLOR_ID=@NJL_LOCAL_COLOR_ID,");
			strSql.Append("SEO_TITLE=@SEO_TITLE,");
			strSql.Append("SEO_KEYWORDS=@SEO_KEYWORDS,");
			strSql.Append("SEO_DESCRIPTION=@SEO_DESCRIPTION,");
			strSql.Append("NEWS_TITLE=@NEWS_TITLE,");
			strSql.Append("NEWS_SUBJECT_TITLE=@NEWS_SUBJECT_TITLE,");
			strSql.Append("NEWS_CONTECT=@NEWS_CONTECT,");
			strSql.Append("NEWS_TAG=@NEWS_TAG,");
			strSql.Append("CREATE_DATE_TIME=@CREATE_DATE_TIME,");
			strSql.Append("CREATE_USER_ID=@CREATE_USER_ID,");
			strSql.Append("CREATE_USER_NAME=@CREATE_USER_NAME,");
			strSql.Append("UPDATE_DATE_TIME=@UPDATE_DATE_TIME,");
			strSql.Append("UPDATE_USER_ID=@UPDATE_USER_ID,");
			strSql.Append("UPDATE_USER_NAME=@UPDATE_USER_NAME,");
			strSql.Append("SORT=@SORT,");
			strSql.Append("VISIT_COUNT=@VISIT_COUNT,");
			strSql.Append("COMMENT_COUNT=@COMMENT_COUNT,");
			strSql.Append("LAST_COMMENT_DATE_TIME=@LAST_COMMENT_DATE_TIME,");
			strSql.Append("LAST_VISIT_DATE_TIME=@LAST_VISIT_DATE_TIME,");
			strSql.Append("IMAGE_CODE=@IMAGE_CODE");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@NJL_LOCAL_COLOR_ID", SqlDbType.VarChar,20),
					new SqlParameter("@SEO_TITLE", SqlDbType.VarChar,200),
					new SqlParameter("@SEO_KEYWORDS", SqlDbType.VarChar,200),
					new SqlParameter("@SEO_DESCRIPTION", SqlDbType.VarChar,500),
					new SqlParameter("@NEWS_TITLE", SqlDbType.VarChar,100),
					new SqlParameter("@NEWS_SUBJECT_TITLE", SqlDbType.VarChar,1000),
					new SqlParameter("@NEWS_CONTECT", SqlDbType.Text),
					new SqlParameter("@NEWS_TAG", SqlDbType.VarChar,200),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@SORT", SqlDbType.Int,4),
					new SqlParameter("@VISIT_COUNT", SqlDbType.Int,4),
					new SqlParameter("@COMMENT_COUNT", SqlDbType.Int,4),
					new SqlParameter("@LAST_COMMENT_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@LAST_VISIT_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@IMAGE_CODE", SqlDbType.VarChar,500),
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = model.NJL_LOCAL_COLOR_ID;
			parameters[1].Value = model.SEO_TITLE;
			parameters[2].Value = model.SEO_KEYWORDS;
			parameters[3].Value = model.SEO_DESCRIPTION;
			parameters[4].Value = model.NEWS_TITLE;
			parameters[5].Value = model.NEWS_SUBJECT_TITLE;
			parameters[6].Value = model.NEWS_CONTECT;
			parameters[7].Value = model.NEWS_TAG;
			parameters[8].Value = model.CREATE_DATE_TIME;
			parameters[9].Value = model.CREATE_USER_ID;
			parameters[10].Value = model.CREATE_USER_NAME;
			parameters[11].Value = model.UPDATE_DATE_TIME;
			parameters[12].Value = model.UPDATE_USER_ID;
			parameters[13].Value = model.UPDATE_USER_NAME;
			parameters[14].Value = model.SORT;
			parameters[15].Value = model.VISIT_COUNT;
			parameters[16].Value = model.COMMENT_COUNT;
			parameters[17].Value = model.LAST_COMMENT_DATE_TIME;
			parameters[18].Value = model.LAST_VISIT_DATE_TIME;
			parameters[19].Value = model.IMAGE_CODE;
			parameters[20].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_LOCAL_COLOR_NEWS ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_LOCAL_COLOR_NEWS ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_LOCAL_COLOR_NEWS GetModel(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,NJL_LOCAL_COLOR_ID,SEO_TITLE,SEO_KEYWORDS,SEO_DESCRIPTION,NEWS_TITLE,NEWS_SUBJECT_TITLE,NEWS_CONTECT,NEWS_TAG,CREATE_DATE_TIME,CREATE_USER_ID,CREATE_USER_NAME,UPDATE_DATE_TIME,UPDATE_USER_ID,UPDATE_USER_NAME,SORT,VISIT_COUNT,COMMENT_COUNT,LAST_COMMENT_DATE_TIME,LAST_VISIT_DATE_TIME,IMAGE_CODE from NJL_LOCAL_COLOR_NEWS ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			NJL.Model.NJL_LOCAL_COLOR_NEWS model=new NJL.Model.NJL_LOCAL_COLOR_NEWS();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NJL_LOCAL_COLOR_ID"]!=null && ds.Tables[0].Rows[0]["NJL_LOCAL_COLOR_ID"].ToString()!="")
				{
					model.NJL_LOCAL_COLOR_ID=ds.Tables[0].Rows[0]["NJL_LOCAL_COLOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SEO_TITLE"]!=null && ds.Tables[0].Rows[0]["SEO_TITLE"].ToString()!="")
				{
					model.SEO_TITLE=ds.Tables[0].Rows[0]["SEO_TITLE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SEO_KEYWORDS"]!=null && ds.Tables[0].Rows[0]["SEO_KEYWORDS"].ToString()!="")
				{
					model.SEO_KEYWORDS=ds.Tables[0].Rows[0]["SEO_KEYWORDS"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SEO_DESCRIPTION"]!=null && ds.Tables[0].Rows[0]["SEO_DESCRIPTION"].ToString()!="")
				{
					model.SEO_DESCRIPTION=ds.Tables[0].Rows[0]["SEO_DESCRIPTION"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NEWS_TITLE"]!=null && ds.Tables[0].Rows[0]["NEWS_TITLE"].ToString()!="")
				{
					model.NEWS_TITLE=ds.Tables[0].Rows[0]["NEWS_TITLE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NEWS_SUBJECT_TITLE"]!=null && ds.Tables[0].Rows[0]["NEWS_SUBJECT_TITLE"].ToString()!="")
				{
					model.NEWS_SUBJECT_TITLE=ds.Tables[0].Rows[0]["NEWS_SUBJECT_TITLE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NEWS_CONTECT"]!=null && ds.Tables[0].Rows[0]["NEWS_CONTECT"].ToString()!="")
				{
					model.NEWS_CONTECT=ds.Tables[0].Rows[0]["NEWS_CONTECT"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NEWS_TAG"]!=null && ds.Tables[0].Rows[0]["NEWS_TAG"].ToString()!="")
				{
					model.NEWS_TAG=ds.Tables[0].Rows[0]["NEWS_TAG"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString()!="")
				{
					model.CREATE_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATE_USER_ID"]!=null && ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString()!="")
				{
					model.CREATE_USER_ID=ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_USER_NAME"]!=null && ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString()!="")
				{
					model.CREATE_USER_NAME=ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString()!="")
				{
					model.UPDATE_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATE_USER_ID"]!=null && ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString()!="")
				{
					model.UPDATE_USER_ID=ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_USER_NAME"]!=null && ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString()!="")
				{
					model.UPDATE_USER_NAME=ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SORT"]!=null && ds.Tables[0].Rows[0]["SORT"].ToString()!="")
				{
					model.SORT=int.Parse(ds.Tables[0].Rows[0]["SORT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["VISIT_COUNT"]!=null && ds.Tables[0].Rows[0]["VISIT_COUNT"].ToString()!="")
				{
					model.VISIT_COUNT=int.Parse(ds.Tables[0].Rows[0]["VISIT_COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["COMMENT_COUNT"]!=null && ds.Tables[0].Rows[0]["COMMENT_COUNT"].ToString()!="")
				{
					model.COMMENT_COUNT=int.Parse(ds.Tables[0].Rows[0]["COMMENT_COUNT"].ToString());
				}
				if(ds.Tables[0].Rows[0]["LAST_COMMENT_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["LAST_COMMENT_DATE_TIME"].ToString()!="")
				{
					model.LAST_COMMENT_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["LAST_COMMENT_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["LAST_VISIT_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["LAST_VISIT_DATE_TIME"].ToString()!="")
				{
					model.LAST_VISIT_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["LAST_VISIT_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IMAGE_CODE"]!=null && ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString()!="")
				{
					model.IMAGE_CODE=ds.Tables[0].Rows[0]["IMAGE_CODE"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,NJL_LOCAL_COLOR_ID,SEO_TITLE,SEO_KEYWORDS,SEO_DESCRIPTION,NEWS_TITLE,NEWS_SUBJECT_TITLE,NEWS_CONTECT,NEWS_TAG,CREATE_DATE_TIME,CREATE_USER_ID,CREATE_USER_NAME,UPDATE_DATE_TIME,UPDATE_USER_ID,UPDATE_USER_NAME,SORT,VISIT_COUNT,COMMENT_COUNT,LAST_COMMENT_DATE_TIME,LAST_VISIT_DATE_TIME,IMAGE_CODE ");
			strSql.Append(" FROM NJL_LOCAL_COLOR_NEWS ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,NJL_LOCAL_COLOR_ID,SEO_TITLE,SEO_KEYWORDS,SEO_DESCRIPTION,NEWS_TITLE,NEWS_SUBJECT_TITLE,NEWS_CONTECT,NEWS_TAG,CREATE_DATE_TIME,CREATE_USER_ID,CREATE_USER_NAME,UPDATE_DATE_TIME,UPDATE_USER_ID,UPDATE_USER_NAME,SORT,VISIT_COUNT,COMMENT_COUNT,LAST_COMMENT_DATE_TIME,LAST_VISIT_DATE_TIME,IMAGE_CODE ");
			strSql.Append(" FROM NJL_LOCAL_COLOR_NEWS ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "NJL_LOCAL_COLOR_NEWS";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

